﻿using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Collections.Generic;
using System.Windows.Media;
using TheVerge.Base.Models;
using TheVerge.Phone.Controls;
using TheVerge.Phone.Imp;
using TheVerge.Phone.Pages;

namespace TheVerge.Phone
{
    public partial class NewsPage : MainPage
    {

        public NewsPage()
        {
            InitializeComponent();
            news.SetPage(this);
            DataContext = App.MainVM;
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (news.IsArticleVisible)
            {
                news.HideArticle();
                e.Cancel = true;
                return;
            }
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            App.MainVM.ActivePinnable = App.MainVM.News;
            news.RefreshActiveArticle();
        }

        protected override MainPage.PageSection Section
        {
            get { return MainPage.PageSection.News; }
        }

        protected override void LoadFromQueryStrings(Dictionary<string, string> queryStrings)
        {
            App.MainVM.News.LoadFromPin(queryStrings);
        }
    }
}